home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 46
/
Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso
/
-in_the_mag-
/
reader_requests
/
amiga-e
/
tools
/
brush2e.e
< prev
Wrap
Text File
|
1999-09-13
|
7KB
|
165 lines
/*
** This little program can be used to convert an ILBM brush
** to something that MUI's Bodychunk class can understand.
** For easy useage, an emodule-source is generated.
**
** This tool is written by Jan Hendrik Schulz
** It is based on brush2c by Stefan Stuntz
**
*/
OPT PREPROCESS
MODULE 'exec/types'
MODULE 'libraries/iffparse'
MODULE 'datatypes/pictureclass'
MODULE 'graphics/gfx'
MODULE 'iffparse'
#define to32(c) (Shl(c,24) OR Shl(c,16) OR Shl(c,8) OR c)
PROC main()
DEF name[100]:STRING,uname[50]:STRING,c
DEF iff:PTR TO iffhandle
DEF cn:PTR TO contextnode, cn2:PTR TO contextnode
DEF sp:PTR TO storedproperty
DEF bmhd:PTR TO bitmapheader
DEF body,size,i,cols
DEF myargs:PTR TO LONG,rdargs
DEF buf[200]:STRING,colors=FALSE
DEF outfile
myargs:=[0,0,0]
IF (rdargs:=ReadArgs('ILBMFILE/A,EMODSRC/A,NOHEADER/S',myargs,NIL))=NIL
WriteF('Bad Args!\n')
RETURN 20
ENDIF
c:=myargs[0]
IF (i:=InStr(c,':'))<>-1 THEN c:=c+i+1
WHILE (i:=InStr(c,'/'))<>-1 DO c:=c+i+1
StrCopy(name,c)
IF (c:=InStr(name,'.'))<>-1
name[c]:=0
SetStr(name,StrLen(name))
ENDIF
StrCopy(uname,name)
UpperStr(uname)
IF (name[]>="a") AND (name[]<="z") THEN name[]:=name[]-32
IF iffparsebase:=OpenLibrary('iffparse.library',36)
IF outfile:=Open(myargs[1],NEWFILE)
IF iff:=AllocIFF()
iff.stream:=Open(myargs[0],OLDFILE)
IF iff.stream
InitIFFasDOS(iff)
IF OpenIFF(iff,IFFF_READ)=0
IF ParseIFF(iff,IFFPARSE_STEP)=0
IF (cn:=CurrentChunk(iff)) AND (cn.id=ID_FORM)
IF cn.type=ID_ILBM
IF (PropChunk(iff,ID_ILBM,ID_BMHD) OR
PropChunk(iff,ID_ILBM,ID_CMAP) OR
StopChunk(iff,ID_ILBM,ID_BODY) OR
StopOnExit(iff,ID_ILBM,ID_FORM) OR
ParseIFF(iff,IFFPARSE_SCAN))=0
Fputs(outfile,'-> EModule with imagedatas for MUI - generated by brush2e.\n\n')
Fputs(outfile,'OPT MODULE\nOPT EXPORT\nOPT PREPROCESS\n\n')
IF Not(myargs[2])
Fputs(outfile,'MODULE \adatatypes/pictureclass\a\n')
ENDIF
Fputs(outfile,'MODULE \amuimaster\a, \alibraries/mui\a\n')
Fputs(outfile,'MODULE \autility/tagitem\a\n\n')
IF sp:=FindProp(iff,ID_ILBM,ID_BMHD)
bmhd := sp.data
IF (bmhd.compression=CMPNONE) OR (bmhd.compression=CMPBYTERUN1)
cn2:=CurrentChunk(iff)
size := cn2.size
IF body:=New(size)
IF ReadChunkBytes(iff,body,size)=size
PrintF('Width \d Height \d Depth \d - converting...\n',bmhd.width,bmhd.height,bmhd.depth)
StringF(buf,'CONST IMG_\s_WIDTH = \d[3]\n',uname,bmhd.width)
Fputs(outfile,buf)
StringF(buf,'CONST IMG_\s_HEIGHT = \d[3]\n',uname,bmhd.height)
Fputs(outfile,buf)
StringF(buf,'CONST IMG_\s_DEPTH = \d[3]\n',uname,bmhd.depth)
Fputs(outfile,buf)
StringF(buf,'CONST IMG_\s_COMPRESSION = \d[3]\n',uname,bmhd.compression)
Fputs(outfile,buf)
StringF(buf,'CONST IMG_\s_MASKING = \d[3]\n\n',uname,bmhd.masking)
Fputs(outfile,buf)
IF Not(myargs[2])
StringF(buf,'PROC img\sHeader() IS ',name)
Fputs(outfile,buf)
StringF(buf,'[\d,\d,\d,\d,\d,\d,\d,0,\d,\d,\d,\d,\d]:bitmapheader\n\n',bmhd.width,bmhd.height,bmhd.left,bmhd.top,bmhd.depth,bmhd.masking,bmhd.compression,bmhd.transparent,bmhd.xaspect,bmhd.yaspect,bmhd.pagewidth,bmhd.pageheight)
Fputs(outfile,buf)
ENDIF
StringF(buf,'PROC img\sBody() IS\n [',name)
Fputs(outfile,buf)
FOR i:=0 TO size-2
StringF(buf,'$\z\h[2],',body[i])
Fputs(outfile,buf)
IF Mod(i+1,15)=0 THEN Fputs(outfile,'\n ')
ENDFOR
StringF(buf,'$\z\h[2]]:CHAR\n\n',body[size-1])
Fputs(outfile,buf)
ENDIF
Dispose(body)
ENDIF
ENDIF
ENDIF
IF sp:=FindProp(iff,ID_ILBM,ID_CMAP)
cols := sp.data
StringF(buf,'PROC img\sColors() IS\n [',name)
Fputs(outfile,buf)
FOR i:=0 TO sp.size-4 STEP 3
StringF(buf,'$\z\h[8],$\z\h[8],$\z\h[8],\n ',to32(cols[i]),to32(cols[i+1]),to32(cols[i+2]))
Fputs(outfile,buf)
ENDFOR
StringF(buf,'$\z\h[8],$\z\h[8],$\z\h[8]]\n\n',to32(cols[i]),to32(cols[i+1]),to32(cols[i+2]))
Fputs(outfile,buf)
colors:=TRUE
ENDIF
StringF(buf,'PROC img\sObject() IS\n BodychunkObject,\n',name); Fputs(outfile,buf)
StringF(buf,' MUIA_Bodychunk_Body, img\sBody(),\n',name); Fputs(outfile,buf)
StringF(buf,' MUIA_Bodychunk_Masking, IMG_\s_MASKING,\n',uname); Fputs(outfile,buf)
StringF(buf,' MUIA_Bodychunk_Compression, IMG_\s_COMPRESSION,\n',uname); Fputs(outfile,buf)
StringF(buf,' MUIA_Bodychunk_Depth, IMG_\s_DEPTH,\n',uname); Fputs(outfile,buf)
StringF(buf,' MUIA_Bitmap_Height, IMG_\s_HEIGHT,\n',uname); Fputs(outfile,buf)
StringF(buf,' MUIA_Bitmap_Width, IMG_\s_WIDTH,\n',uname); Fputs(outfile,buf)
StringF(buf,' MUIA_FixHeight, IMG_\s_HEIGHT,\n',uname); Fputs(outfile,buf)
StringF(buf,' MUIA_FixWidth, IMG_\s_WIDTH,\n',uname); Fputs(outfile,buf)
IF colors
StringF(buf,' MUIA_Bitmap_SourceColors, img\sColors(),\n',name); Fputs(outfile,buf)
ENDIF
Fputs(outfile,' End\n\n')
ENDIF
ENDIF
ENDIF
ENDIF
CloseIFF(iff)
ENDIF
Close(iff.stream)
ENDIF
FreeIFF(iff)
ENDIF
Close(outfile)
ENDIF
CloseLibrary(iffparsebase)
ENDIF
FreeArgs(rdargs)
ENDPROC 0